﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.InteropServices;

namespace Demo
{
    class Program
    {
        [DllImport("sdk.dll", EntryPoint = "sdknotify")]
        public static extern IntPtr sdknotify();

        [DllImport("sdk.dll", EntryPoint = "sdkcommand", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr sdkcommand(string strCommand);

        //thread to read the sdk notify
        public static void ThreadMethod(object parameter)
        {
            while (true)
            {
                IntPtr ret = sdknotify();
                string strRet = Marshal.PtrToStringAnsi(ret);
                Console.WriteLine(strRet);
            }
        }

        static void Main(string[] args)
        {
            //read the notify from another thread
            Thread thread = new Thread(ThreadMethod);
            thread.Start();

            //SDK init
            IntPtr result = sdkcommand("init -node 2 -ip 192.168.0.197 -debug -path C:\\Users\\Administrator\\Documents\\ZIBON\\AudioServer\\config\\");
            string strRet = Marshal.PtrToStringAnsi(result);
            Console.WriteLine(strRet);

            Console.Write("#");
            while (true)
            {
                string str = Console.ReadLine();
                if (str.Length == 0)
                {
                    Console.Write("#");
                    continue;
                }
                IntPtr result2 = sdkcommand(str);
                string strRet2 = Marshal.PtrToStringAnsi(result2);
                Console.WriteLine(strRet2);
                Console.Write("#");
            }
        }
    }
}
